<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">

        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="row">
                            <div class="col-sm-9">
                            </div>

                        </div>
                    </div>
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <thead>
                            <tr>
                                <th>日期</th>
                                <th>关键字</th>
                                <th>对象的ID</th>
                                <th>添加时间</th>
                                <th>状态</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodycontent">


                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                    <div id="pagecontent" class="pagination"></div>
                </div><!-- /.box -->
            </div>
        </div>
    </section>

</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script type="text/javascript">
        var history_data = {
        };

        function searchHistroy() {
            history_data = {
                show:-1,
                date:'',
                pno: 1,
                pagesize: 10,
                allcount:-1
            };
            LoadHistroyList();
        }
        //加载列表
        searchHistroy();
        function LoadHistroyList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/histroy/list',
                    data: history_data,
                    dataType: 'json',
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {
                                history_data.allcount = data.result.count;
                                var html = '';
                                $.each(data.result.list, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);
                                ShowPage('pagecontent', history_data, function (pno) {
                                    history_data.pno = pno;
                                    LoadHistroyList();
                                });
                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function  getHtml(dataObject) {
            var stateHtml='';
            if (dataObject.fShow==0){
                stateHtml= '<span class="label label-success">显示</span>'
            }
            else if (dataObject.fShow=='1'){
                stateHtml= '<span class="label label-danger">隐藏</span>'

            }
            return ' <tr>'+
                '<td>'+dataObject.fDate.substring(0,2)+'月'+dataObject.fDate.substr(2)+'日</td>'+
                '<td>'+dataObject.fKeyword+'</td>'+
                '<td>'+dataObject.fObjectid+'</td>'+
                '<td>'+dataObject.fIntime+'</td>'+
                '<td>'+stateHtml+'</td>'+
                '<td><a style="cursor: pointer" href="/page/histroy/update?fid='+dataObject.fId+'" >修改</a>' +
                '</td>'+
                '<td><a style="cursor: pointer" href="#" onclick="UpdateState(\''+dataObject.fId+'\',0)">显示</a>' +
                '</td>'+
                '<td><a style="cursor: pointer" href="#" onclick="UpdateState(\''+dataObject.fId+'\',1)">隐藏</a>' +
                '</td>'+
                '</tr>';
        }
        function UpdateState(fid,state) {
            $.ajax({
                    url: '/api/histroy/updatestate',
                    data: {fid: fid,state:state},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadHistroyList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>